import time
from concurrent.futures import ThreadPoolExecutor, wait

import numpy as np
import pandas as pd


def main():
    # pass
    test6()


def test1():
    n = 1234567890.123456789012345
    "{:.9e}".format(n)
    print(n)


def test2():
    a = np.array([2, 4, 6, 8, 10])
    b = np.where(a > 5, None)  # 返回索引
    print(b)


def test3():
    for a in range[0, 10]:
        b += a
        print(a)


def test4():
    foo4_1("aaa")


def foo4_1(a):
    foo4_1(a, "123")


def foo4_1(a, b):
    print(a)
    print(b)


def test5():
    a, b = test5_1()
    print(a)
    print(b)


def test5_1():
    return "123", 18


def test6():
    cache = pd.DataFrame(columns=['road', 'laneId', 'x', 'y', 'z', 'lng', 'lat', 'nodeDistance'])
    cache.append([{'road': 1, 'laneId': 1, 'x': 1, 'y': 1, 'z': 1, 'lng': 1, 'lat': 1, 'nodeDistance': 1}],
                 ignore_index=True)
    cache.append([{'road': 2, 'laneId': 2, 'x': 2, 'y': 2, 'z': 2, 'lng': 2, 'lat': 2, 'nodeDistance': 2}],
                 ignore_index=True)
    cache = cache.iloc[::-1]
    pass


def test7():
    str1 = '55.48174895321206 36.5597716795688 -3.753951,52.00071789340276 37.742795776619836 -3.795933465062289,50.62153166008882 38.461017673210826 -3.8349510000000007,'
    str1 = str1[:str1.find(',')]
    print(str1)


def test8():
    str1 = None
    str2 = str(str1)
    print(str2)


def test9():
    str1 = "123456_2"
    str2 = str(str1[:str1.find("_") - len(str1)])
    print(str2)


def sayhello(a):
    ll = []
    print("hello: " + a)
    ll.append(a)
    time.sleep(0.8)


def main():
    seed = ["a", "b", "c", "e", "f", "g", "h"]
    start1 = time.time()
    for each in seed:
        sayhello(each)
        end1 = time.time()
        print("time1: " + str(end1 - start1))
    start2 = time.time()
    with ThreadPoolExecutor(2) as executor:
        for each in seed:
            executor.submit(sayhello, each)
    end2 = time.time()
    print("time2: " + str(end2 - start2))


def main2():
    seed = ["a", "b", "c", "e", "f", "g", "h"]
    executor = ThreadPoolExecutor(max_workers=10)
    f_list = []
    for each in seed:
        future = executor.submit(sayhello, each)
        f_list.append(future)
        wait(f_list)
        print(ll)
    print('主线程结束')


def main3():
    seed = ["a", "b", "c", "e", "f", "g", "h"]
    with ThreadPoolExecutor(max_workers=2) as executor:
        f_list = []
        for each in seed:
            future = executor.submit(sayhello, each)
            f_list.append(future)
            wait(f_list, return_when='ALL_COMPLETED')
            print(ll)
    print('主线程结束')


if __name__ == '__main__':
    test9()
